package com.lfy.ai.weny;

import com.alibaba.dashscope.common.Message;
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.baidubce.qianfan.model.chat.ChatUsage;
import com.lfy.ai.AiChatStandard;
import com.lfy.ai.qwen.QwenGroupDialogue;
import com.lfy.modules.common.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 文心一言接入
 *
 * @author <a href="https://www.lvfeiy.top">lvfeiyang</a>
 * @date 2024/6/28 13:11
 */
@Slf4j
@Component
@ConditionalOnProperty(name = "ai.weny.enable", havingValue = "true", matchIfMissing = false)
@Import({WenyGroupDialogue.class})
public class WenyChat extends AiChatStandard {
    @Override
    protected boolean choice(Integer aiCode) {
        return false;
    }

    @Override
    public void ask(String question, Integer aiModelCode, String clientId, Integer groupId, String url) {
        Qianfan qianfan = new Qianfan("", "");

        // 指定模型
        qianfan.chatCompletion()
                .model("ERNIE-3.5-8K")
                .addMessage("user","你好")
                .executeStream()
                .forEachRemaining(chunk -> System.out.print(JsonUtils.toStr(chunk)));


    }

    @Override
    public Integer tokenizer(String question, Integer aiModelType) {
        return null;
    }

    public static void main(String[] args) {
        Qianfan qianfan = new Qianfan("", "");

        // 指定模型
        qianfan.chatCompletion()
                .model("ERNIE-3.5-8K")
                .addMessage("user","你好")
                .executeStream()
                .forEachRemaining(chunk -> System.out.print(JsonUtils.toStr(chunk)));
    }


    @Override
    protected void tokenizerAfter(Integer modelType, List<Message> messages, String url) {

    }


}
